Fix section type identifing in mach-o view#7842
Conversation
|
Thank you for sending this PR. The change seems correct, but I do want to look into why this existing code was matching on section names before I merge it. Is there a particular Mach-O binary on which you noticed the incorrect section type handling causing a problem? |
|
The mach-o I analyzed is a 2023 iOS in-the-wild (ITW) malware sample called Predator. It was uploaded and shared by Google GTIG/TAG; their blog post is available here. The sample can be downloaded here. I loaded the sample into Binary Ninja and noticed that the entire Support for the One more issue is that I missed |
|
Thank you again for the PR, and for your patience as I followed up on it. A bug was reported via Slack (#7891) that looks like it requires a change in how we classify sections, and it took some time to make sure I understood how a fix for it would interact with the changes proposed here. Additionally, I noticed that your second commit introduced a bug due to operator precedence: is interpreted as: which is What I propose doing is:
Something like this: I'm happy to make these changes myself on your branch prior to merging, or for you to make them. |
|
I fully agree with your proposal. The code has been commited. |
1. A section's `flags` are masked with `SECTION_TYPE` before being compared. This prevents misclassifying a section when its low bits are shared with other section types. 2. `__mod_init_func` and `__init_offsets` are identified by section type flags, rather than by name. There's no documented reason why these were being matched by name. 3. A fallback is added to detect `__got` sections by name. This is necessary as some kext bundles that have their `__got` sections as `S_REGULAR` rather than `S_NON_LAZY_SYMBOL_POINTERS`. This fixes Vector35#7891. Thanks to @WHW0x455 for these fixes.
|
I restored the Thanks again for the fix and for being so responsive to feedback! |
|
These changes are in 5.3.8952-dev and newer. |
The patch is only tested on 5.2.8614.
Based on opensource code
loader.handdyld, the lowest byte insect.flagsstands for section type.__auth_gotor__got__init_offsetsThe problem for
sect.flags & S_NON_LAZY_SYMBOL_POINTERSis that ifflagsisS_INIT_FUNC_OFFSETS, mach-o view will confuse__init_offsetswith__auth_got(or__got). The checks for other section types have also been improved.